/*
 *  
 *    !! EVENTS !!
 * 
 */

/*
 *  Scroll to test
 */

$('#scrollbutton').click(function(e){
  scrollTo("scrolldestination");
})

/*
 *  Search location
 */

$('body').on('submit', '#search_location', function () {
	var string = $('#location_string').val();
	if($('#location_string').val() == '')
	{
		display_alert('Enter a location', '#alert_area', 'warning');
	}
	else
	{
		location_search(string);
	}
	return false;
});

$('body').on('click', '#find_me', function () {
	MM.locate('here');
	return false;
});

/*
 *  Search object
 */

$('body').on('keyup', '#search_string', function () {
	var string = $('#search_string').val();
	if($('#search_string').val() == '')
	{
		ObjectManager.displayList();
	}
	else
	{
		object_search(string);
	}
});

$('body').on('submit', '#search_object', function () {
	var string = $('#search_string').val();
	if($('#search_string').val() == '')
	{
		ObjectManager.displayList();
	}
	else
	{
		object_search(string);
	}
	return false;
});

$('body').on('keyup', '#msearch_string', function () {
	var string = $('#msearch_string').val();
	if($('#msearch_string').val() == '')
	{
		ObjectManager.displayList();
	}
	else
	{
		object_search(string);
	}
});

/*
 *  Register object
 */

$('#add_object_button').click(function() {
	
	if($('#add_object_button').html() == 'Cancel')
	{
		IC.cancel_create();
	}
	else
	{
		IC.init_create();
	}
});

$("form_object_create").submit(function()
{
	// upload files
	
	//object_create();
});

/*
 *  Content loader
 *  Hard coding to avoid js inclusion
 */

$('a[data-action=load][href=#list]').click(function() {
	$('a[data-action=load]').parent().toggleClass('active');
	$('#contentMain').html('<img class="center" src="assets/img/ajax-loader.gif">');
	$('#contentMain').load('pages/view_part/list', function() {
		ObjectManager.setPage('0');
		param = '0';
		ObjectManager.displayList();
		refreshList(sortBy);
	});
	switchInterface('content');
});


$('a[data-action=load][href=#ulist]').click(function() {
	$('a[data-action=load]').parent().toggleClass('active');
	$('#contentMain').html('<img class="center" src="assets/img/ajax-loader.gif">');
	$('#contentMain').load('pages/view_part/ulist', function() {
		ObjectManager.setPage('m');
		param = 'm';
		ObjectManager.displayList();
		refreshList(sortBy);
	});
	switchInterface('content');
});

// allow multiple modal by removing content
$('body').on('hidden', '.modal', function () {
	  $(this).removeData('modal');
});